<fieldset>

    <legend>条件搜索</legend>

    <form class="layui-form layui-form-pane form-search" id="singcms-form" action="{:request()->url()}" onsubmit="return false" method="get" autocomplete="off">

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">受访人</label>
            <div class="layui-input-inline">
                <input name="user_name" value="{$Think.get.user_name|default=''}" placeholder="请输入受访人名称" class="layui-input">
            </div>
        </div>
{if $userinfo['db1']['authorize'] == 1}
				<div class="layui-form-item layui-inline">
		    <label class="layui-form-label">到访公司</label>
		    <div class="layui-input-inline">
		        <input name="address" value="{$Think.get.address|default=''}" placeholder="请输入到访公司名称" class="layui-input">
		    </div>
		</div>
    {/if}
		<div class="layui-form-item layui-inline">
		    <label class="layui-form-label">到访部门</label>
		    <div class="layui-input-inline">
		        <input name="address" value="{$Think.get.address|default=''}" placeholder="请输入到访部门名称" class="layui-input">
		    </div>
		</div>
		
  <!--       <div class="layui-form-item layui-inline">
            <label class="layui-form-label">受访目的</label>
            <div class="layui-input-inline">
                <input name="reson" value="{$Think.get.reson|default=''}"  placeholder="请输入拜访目的" class="layui-input">
            </div>
        </div> -->

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">到访情况</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="status">
                    {foreach [''=>'-- 全部状态 --','0'=>'邀请未完成','1'=>'邀请完成'] as $k=>$v}
                    {eq name='Think.get.status' value='$k.""'}
                    <option selected value="{$k}">{$v}</option>
                    {else}
                    <option value="{$k}">{$v}</option>
                    {/eq}
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">排序字段</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="order_column">
                    {foreach ['visittime'=>'预约时间','id'=>'序号'] as $k=>$v}
                    {eq name='Think.get.status' value='$k.""'}
                    <option selected value="{$k}">{$v}</option>
                    {else}
                    <option value="{$k}">{$v}</option>
                    {/eq}
                    {/foreach}
                </select>
            </div>
        </div>
       <div class="layui-form-item layui-inline">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="order">
                    {foreach ['desc'=>'倒序','asc'=>'顺序'] as $k=>$v}
                    {eq name='Think.get.status' value='$k.""'}
                    <option selected value="{$k}">{$v}</option>
                    {else}
                    <option value="{$k}">{$v}</option>
                    {/eq}
                    {/foreach}
                </select>
          </div>
        </div>
		        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">选择日期</label>
            <div class="layui-input-block">
      <input type="radio" name="checkdate" lay-filter="checkdate" value="day" title="当日">
      <input type="radio" name="checkdate" lay-filter="checkdate" value="week" title="本周">
      <input type="radio" name="checkdate" lay-filter="checkdate" value="month" title="本月">
      <input type="radio" name="checkdate" lay-filter="checkdate" value="last_month" title="上月">
      <input type="radio" name="checkdate" lay-filter="checkdate" value="otherdate" title="其他" checked>
            </div>

		</div>

		
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">预约时间</label>
            <div class="layui-input-inline">
				  <input type="text" class="layui-input" id="create_at_first" name="create_at_first" value="{$Think.get.create_at_first|default=''}"  placeholder="请选择时间">			 
            </div>
		  <div class="layui-form-mid">—</div>
			   <div class="layui-input-inline">
			<input type="text" class="layui-input" id="create_at_last" name="create_at_last" value="{$Think.get.create_at_last|default=''}"  placeholder="请选择时间">
			</div>
		</div>

 <input type="hidden" name="true_spm" value="m-70-217">
			  <div class="layui-form-item layui-inline">
			    <button class="layui-btn layui-btn-primary" id="singcms-button-submit"><i class="layui-icon">&#xe615;</i> 搜 索</button>
			</div>
    </form>

</fieldset>

<script>form.render()</script>
<script>
layui.use(['laydate','form'], function(){
  var laydate = layui.laydate;
      var form = layui.form;
    var  layer = layui.layer;
 form.on('radio(checkdate)', function (data) {

 	//console.log(data)
	var date = new Date();
 	var create_at_first = $('#create_at_first')
 	var create_at_last = $('#create_at_last')
 	switch(data.value) {
     case 'day':
     	laydate.render({ 
		  elem: '#create_at_first'
		  ,value: new Date(new Date(new Date().toLocaleDateString()).getTime()) //必须遵循format参数设定的格式
		});
		laydate.render({ 
		  elem: '#create_at_last'
		  ,value: new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1) //必须遵循format参数设定的格式
		});
		$('#singcms-button-submit').click();
        break;
	 case 'week':
    	 // 本周一的日期
    	 date.setDate(date.getDate() - date.getDay() + 1);
    	 var begin = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() ;
    	 // + " 00:00:00"
  	 
    	 // 本周日的日期
    	 date.setDate(date.getDate() + 6);
    	 var end = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    	  // + " 23:59:59"

		 laydate.render({ 
		  elem: '#create_at_first'
		  ,value: begin //必须遵循format参数设定的格式
		});
		 laydate.render({ 
		  elem: '#create_at_last'
		  ,value: end //必须遵循format参数设定的格式
		});
		 $('#singcms-button-submit').click();
	 	break;
	 case 'month':
	 	 var nowmonth_first = new Date(date.setDate(1));

      	 var currentMonth=date.getMonth();
      	 var nextMonth=++currentMonth;
      	 var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
      	 var oneDay=1000*60*60*24;
      	 var nowmonth_last = new Date(nextMonthFirstDay-oneDay);
	 	 laydate.render({ 
		  elem: '#create_at_first'
		  ,value: nowmonth_first //必须遵循format参数设定的格式
		});
		 laydate.render({ 
		  elem: '#create_at_last'
		  ,value: nowmonth_last //必须遵循format参数设定的格式
		});
		 $('#singcms-button-submit').click();
	 	break;
	 case 'last_month':

     	let nowdays = new Date();
     	let year = nowdays.getFullYear();
     	let month = nowdays.getMonth();
     	if(month==0){
     	    month=12;
     	    year=year-1;
     	}
     	if (month < 10) {
     	     month = "0" + month;
     	}
     	let firstDayOfPreMonth = year + "-" + month + "-" + "01";
     	let lastDay = new Date(year, month, 0);
     	let lastDayOfPreMonth = year + "-" + month + "-" + lastDay.getDate();
     	firstDayOfPreMonth = firstDayOfPreMonth.toString();
     	lastDayOfPreMonth = lastDayOfPreMonth.toString();
     	this.value4 = [];
     	this.value4.push(firstDayOfPreMonth);
     	this.value4.push(lastDayOfPreMonth);
	 	 laydate.render({ 
		  elem: '#create_at_first'
		  ,value: this.value4[0] //必须遵循format参数设定的格式
		});
		 laydate.render({ 
		  elem: '#create_at_last'
		  ,value: this.value4[1] //必须遵循format参数设定的格式
		});
		 $('#singcms-button-submit').click();
	 	break;
	 case 'otherdate':
		break;
     default:
        ''
	} 


      });

  //执行一个laydate实例
  laydate.render({
    elem: '#create_at_first' //指定元素
  });
   laydate.render({
    elem: '#create_at_last' //指定元素
  });
});
</script>

<script>
	$("#singcms-button-submit").click(function() {
	    var data = $("#singcms-form").serializeArray();
	    postData = {};
	    $(data).each(function(i) {
	        postData[this.name]= this.value;
	    });
		// postData['create_at']=create_at;
	    //console.log(postData);
		
	    // 将获取到的数据post给服务器
	    url = SCOPE.save_url;
	    jump_url = SCOPE.jump_url;
	    $.post(url, postData, function(result) {
	        if (result.code == 200) {
	            //成功
	            return dialog.success(result.message, jump_url);
	        } else if (result.code == 400) {
	            // 失败
	            return dialog.error(result.message);
	        }
	    }, "JSON");
	});
	


</script>
<script>
		var SCOPE = {
		'save_url' : "{:url('invitation/invitation/index')}",
		'jump_url' : "{:url('invitation/invitation/index')}",
	
	};
</script>
